package com.sugar.real.estate.module.business.config;

import com.sugar.real.estate.module.business.util.I18nUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

import javax.validation.Validator;

/**
 * @author Y.sugar
 * @since 2025/8/19 9:45
 */
@Configuration
public class ValidationConfiguration {

    @Bean
    public Validator validator()  {
        // 创建 LocalValidatorFactoryBean 对象
        LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
        // 设置 messageSource 属性，实现 i18 国际化
        validator.setValidationMessageSource(I18nUtil.MESSAGE_SOURCE);
        // 返回
        return validator;
    }
}
